package com.cz.video.website.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.cz.video.common.annotation.LegalValidate;
import com.cz.video.common.annotation.Log;
import com.cz.video.common.core.controller.BaseController;
import com.cz.video.common.core.domain.PageQuery;
import com.cz.video.common.core.domain.R;
import com.cz.video.common.core.page.TableDataInfo;
import com.cz.video.common.enums.BusinessType;
import com.cz.video.common.exception.ServiceException;
import com.cz.video.website.domain.WebsiteSearchLog;
import com.cz.video.website.domain.bo.WebsiteSearchLogBo;
import com.cz.video.website.service.IWebsiteSearchLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 搜索日志表 前端控制器
 * </p>
 *
 * @author LLF
 * @since 2023-10-16
 */
@Tag(name = "搜索日志表")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/website-search-log")
public class WebsiteSearchLogController extends BaseController {
    public final IWebsiteSearchLogService websiteSearchLogService;

    //    @SaCheckPermission("website:SearchLog:add")
    /**
     * 添加搜索日志表
     * @param websiteSearchLog
     * @return
     */
    @SaCheckPermission("website:SearchLog:add")
    @Operation(summary = "添加搜索日志表")
    @Log(title = "添加搜索日志表", businessType = BusinessType.INSERT)
    @PostMapping("")
    @LegalValidate
    public R<Void> add(@RequestBody @Validated WebsiteSearchLog websiteSearchLog){
        return toAjax(websiteSearchLogService.insertSearchLog(websiteSearchLog));
    }

    /**
     * 删除搜索日志表
     * @param id
     * @return
     */
    @SaCheckPermission("website:SearchLog:delete")
    @Operation(summary = "删除搜索日志表")
    @Log(title = "删除搜索日志表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable int id){
        int result = websiteSearchLogService.deleteById(id);
        if (result > 0) {
            return toAjax(result);
        } else {
            throw new ServiceException("删除搜索日志表失败，该搜索日志表不存在。");
        }
    }

    /**
     * 修改搜索日志表
     */
    @Operation(summary = "修改搜索日志表")
    @SaCheckPermission("website:SearchLog:edit")
    @Log(title = "搜索日志表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody WebsiteSearchLogBo websiteSearchLog) {
        return toAjax(websiteSearchLogService.updateSearchLog(websiteSearchLog));
    }

    /**
     * 获取搜索日志表
     */
    @SaCheckPermission("website:SearchLog:list")
    @GetMapping("/list")
    public TableDataInfo list(WebsiteSearchLogBo websiteSearchLog, PageQuery pageQuery) {
        return websiteSearchLogService.selectPageSearchLogList(websiteSearchLog, pageQuery);
    }
}
